package com.yugao.fintech.antelope.pay.payment.process.transfer;

import com.yugao.fintech.antelope.pay.common.service.TransferOrderService;
import com.yugao.fintech.antelope.pay.model.entity.TransferOrder;
import com.yugao.fintech.antelope.pay.payment.model.rqrs.transfer.QueryTransferOrderRQ;
import com.yugao.fintech.antelope.pay.payment.model.rqrs.transfer.QueryTransferOrderRS;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import com.yugao.fintech.framework.core.response.Resp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


@Service
public class QueryTransferOrderProcess {
    @Autowired
    private TransferOrderService transferOrderService;

    /**
     * 查单接口
     */
    public Resp<?> queryTransferOrder(QueryTransferOrderRQ rq){
        if(StringUtils.isAllEmpty(rq.getMchOrderNo(), rq.getTransferNo())){
            throw new BizException("mchOrderNo 和 transferId不能同时为空");
        }

        TransferOrder refundOrder = transferOrderService.queryMchOrder(rq.getMchNo(), rq.getMchOrderNo(), rq.getTransferNo());
        if(refundOrder == null){
            throw new BizException("订单不存在");
        }

        QueryTransferOrderRS bizRes = QueryTransferOrderRS.buildByRecord(refundOrder);
        return Resp.ok(bizRes);
    }
}
